package com.jk.vehicle.mini.controller;

import com.jk.vehicle.core.controller.BaseController;
import com.jk.vehicle.core.entity.Adcode;
import com.jk.vehicle.core.entity.Address;
import com.jk.vehicle.core.entity.ResponseEntity;
import com.jk.vehicle.core.utils.GaoDeMapUtil;
import com.jk.vehicle.mini.dto.MessageNoticeDto;
import com.jk.vehicle.mini.entity.MessageNotice;
import com.jk.vehicle.mini.service.CorpService;
import com.jk.vehicle.mini.service.MessageNoticeService;
import com.jk.vehicle.mini.util.SequenceUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Date;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * This is Description for MessageNoticeController
 *
 * @author Administrator
 * @date 2021/07/06
 */
@Api(value = "消息通知相关接口", tags = "消息通知相关接口")
@RestController
@RequestMapping("/message/notice")
public class MessageNoticeController extends BaseController {

	/**
	 * MessageNoticeService服务
	 */
    @Resource
    private MessageNoticeService messageNoticeService;

    @Resource
    private CorpService corpService;

	/**
	 * 新增messageNotice√
	 * @param messageNoticeDto
	 * @return
	 */
    @ApiOperation(value = "意见反馈", notes = "意见反馈 jiajiang 2021-07-06")
    @PostMapping
    public ResponseEntity add(@RequestBody MessageNoticeDto messageNoticeDto) {
        if (messageNoticeDto.getCorpId().longValue() == 0 || messageNoticeDto.getCorpId() == null) {
            return failResult("厂家id不能为空！");
        }
        if (messageNoticeDto.getCorpId() == -1) {
            return failResult("厂家id不能等于-1！");
        }
        if (messageNoticeDto.getUserId().longValue() == 0 || messageNoticeDto.getUserId() == null) {
            return failResult("用户id不能为空！");
        }
        String dsName = corpService.selectDsNameById(messageNoticeDto.getCorpId());
        Adcode adcode = GaoDeMapUtil.getAdcode(messageNoticeDto.getLng(), messageNoticeDto.getLat());
        Address address = GaoDeMapUtil.getAddress(messageNoticeDto.getLng(), messageNoticeDto.getLat());
        MessageNotice messageNotice = new MessageNotice();
        messageNotice.setTitle(messageNoticeDto.getTitle());
        messageNotice.setType(1);
        messageNotice.setCenter(messageNoticeDto.getLng()+","+messageNoticeDto.getLat());
        messageNotice.setPosition(address.getProvicne()+address.getCity()+address.getDistrict());
        messageNotice.setDetails(messageNoticeDto.getDetails());
        messageNotice.setStatus(0);
        messageNotice.setAdcode(adcode.getDistrictCode());
        messageNotice.setUserId(messageNoticeDto.getUserId());
        messageNotice.setCorpId(messageNoticeDto.getCorpId());
        messageNotice.setId(SequenceUtils.nextId());
        messageNotice.setCreateDate(new Date());
        messageNoticeService.save(messageNotice, dsName);
        return successResult(messageNotice);
    }

}
